%领域平均法去噪
img =imread("img/eight.tif");
subplot(2,3,1);imshow(img),xlabel("原始图像");

ju=imnoise(img,"salt & pepper",0.004);
subplot(2,3,2);imshow(ju),xlabel("噪声图像");
% 均值滤波
K1=filter2(fspecial("average",3),ju);
subplot(2,3,3);imshow(uint8(K1)),xlabel("3*3卷积和均值滤波");

K2=filter2(fspecial("average",5),ju);
subplot(2,3,4);imshow(uint8(K2)),xlabel("5*5卷积和均值滤波");

%卷积和 或模板
mask4=[ 0 1 0
        1 0 1
        0 1 0];
mask4=1/4*mask4;
K3=filter2(mask4,ju);
subplot(2,3,5);imshow(uint8(K3)),xlabel("4邻域卷积和均值滤波");


mask8=[ 1 1 1
        1 0 1
        1 1 1];
mask8=1/8*mask8;
K4=filter2(mask8,ju);
subplot(2,3,6);imshow(uint8(K4)),xlabel("8邻域卷积和均值滤波");
